[linux] Display connection state for UDP sockets#358
Open
kurok wants to merge 2 commits intolsof-org:masterfrom
Open
[linux] Display connection state for UDP sockets#358kurok wants to merge 2 commits intolsof-org:masterfrom
kurok wants to merge 2 commits intolsof-org:masterfrom
Conversation
Register UDP socket states in build_IPstates() so that connected UDP sockets (those that called connect()) display (ESTABLISHED), matching the behavior of netstat and ss. Linux /proc/net/udp reuses TCP state enum values: TCP_ESTABLISHED for connected sockets and TCP_CLOSE for unconnected ones. Only ESTABLISHED is registered; unconnected sockets remain displayed without a state to avoid noise. Update text, field (-F), and JSON (-j) output paths to handle UDP states via the existing UdpSt[] infrastructure. Add test case-20-udp-socket-state.bash to verify connected UDP sockets show (ESTABLISHED) in lsof output. Closes lsof-org#287
Use sleep as stdin instead of /dev/zero for nc UDP connections. ncat sends /dev/zero as a single datagram causing "Message too long" on UDP sockets. sleep keeps the process alive without flooding data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Display connection state for UDP sockets in lsof output, addressing the feature request in #287.
connect()) now show(ESTABLISHED), matching the behavior ofnetstatandss-F), and JSON (-j)Before:
After:
Implementation
Linux
/proc/net/udpalready exposes socket state using the sametcp_stateenum values. lsof was already reading and storing these values — it just never displayed them. TheUdpSt[]state table infrastructure already existed inlib/misc.cand was used by other dialects (e.g. Solaris).Changes:
lib/dialects/linux/dsock.c— RegisterESTABLISHEDUDP state inbuild_IPstates()src/dialects/linux/dprint.c— Handlelts.type == 1(UDP) inprint_tcptpi()usingUdpSt[]tablesrc/print.c— Handle UDP states in JSON output pathTest plan
case-20-udp-socket-state.bashtest that creates a connected UDP socket and verifies(ESTABLISHED)appears in lsof output"state":"ESTABLISHED"for connected UDPCloses #287